﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;

namespace Handrise.CDCable.Mobile.Business
{
    /// <summary>
    /// 测温服务
    /// </summary>
    public class TempratureService
    {
        /// <summary>
        /// 获取所有需要上报的测温信息
        /// </summary>
        /// <param name="userName"></param>
        /// <returns></returns>
        public List<Temprature> GetNeedReportTemprature(string userName)
        {
            return AppLogic.dataService.Find<Temprature>("ReportState = '未上报' and UserName ='" + userName + "'", "");
        }

        /// <summary>
        /// 获取所有测温信息
        /// </summary>
        /// <param name="userName"></param>
        /// <returns></returns>
        public List<Temprature> GetAllTemprature(string userName)
        {
            return AppLogic.dataService.Find<Temprature>("UserName ='" + userName + "'", "");
        }

        /// <summary>
        /// 删除测温信息
        /// </summary>
        /// <param name="temperatureID"></param>
        /// <returns></returns>
        public bool DeleteTemperature(string temperatureID)
        {
            return AppLogic.dataService.Delete<Temprature>(temperatureID) == 1;
        }

        public bool AddTemperature(Temprature temperature)
        {
            return AppLogic.dataService.Add<Temprature>(temperature) == 1;
        }

        public bool UpdateTemperature(Temprature temperature)
        {
            return AppLogic.dataService.Update<Temprature>(temperature) == 1;
        }

        public void UpdateReportState(List<Temprature> tempratures, string newState)
        {
            //更新上报状态
            foreach (Temprature temprature in tempratures)
            {
                temprature.ReportState = newState;
                UpdateTemperature(temprature);
            }


        }

        public void DeleteTemperatures(List<Temprature> tempratures)
        {
            foreach (Temprature temprature in tempratures)
            {
                DeleteTemperature(temprature.TempratureID);
            }
        }

    }
}
